#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/9/23 20:13
# @Author  : Crissu
# @Site    : 
# @File    : drawPic.py
# @Software: PyCharm
import os
import os, random
import PIL.Image as Image
import multiprocessing
# folders = os.listdir("C:/sjj/workspace/dataset/linyehaichong/linyehaichong_selected/")
#
# for name in folders:
#     path = "C:/sjj/workspace/dataset/linyehaichong/linyehaichong_addcla/" + name
#     os.makedirs(path)

import re
from pypinyin import pinyin, lazy_pinyin, Style

# s = '10野百合'  # 举个栗子是字符串s，为了匹配下文的unicode形式，所以需要解码
# p = re.compile('[\u4e00-\u9fa5]')  # 这里是精髓，[\u4e00-\u9fa5]是匹配所有中文的正则，因为是unicode形式，所以也要转为ur
# nameList = p.split(s)
# print(nameList)
# name = s[len(nameList[0]):]
#
# print(lazy_pinyin(name))



# path = 'C:/sjj/workspace/dataset/linyehaichong/croped_selected85_resized/'
# classList = os.listdir(path)
# nums = list()
# for name in classList:
#     picPath = path + name + "/"
#     picList = os.listdir(picPath)
#     nums.append(len(picList))
# print(nums)
# print(min(nums))
# print(max(nums))


# a = "\
# [3.]\
# <NDArray 1 @gpu(1)>"
# b = a.split("]")[0].split("[")[1]
# c = b[:len(b)-1]
# print(c)

import cv2
import numpy as np

def random_hsv_transform(img, hue_vari, sat_vari, val_vari):
    hue_delta = np.random.randint(-hue_vari, hue_vari)
    sat_mult = 1 + np.random.uniform(sat_vari, sat_vari)
    val_mult = 1 + np.random.uniform(val_vari, val_vari)
    return hsv_transform(img, hue_delta, sat_mult, val_mult)

def hsv_transform(img, hue_delta, sat_mult, val_mult):
    img_hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV).astype(np.float)
    img_hsv[:, :, 0] = (img_hsv[:, :, 0] + hue_delta) % 180
    img_hsv[:, :, 1] *= sat_mult
    img_hsv[:, :, 2] *= val_mult
    img_hsv[img_hsv > 255] = 255
    return cv2.cvtColor(np.round(img_hsv).astype(np.uint8), cv2.COLOR_HSV2BGR)

def clamp(pv):
    if pv > 255:
        return 255
    elif pv < 0:
        return 0
    else:
        return pv

# 高斯噪声
def gaussian_noise(src):
    image = src
    h, w, c = image.shape
    for row in range(h):
        for col in range(w):
            #获取三个高斯随机数
            #第一个参数：概率分布的均值，对应着整个分布的中心
            #第二个参数：概率分布的标准差，对应于分布的宽度
            #第三个参数：生成高斯随机数数量
            s = np.random.normal(0, 20, 3)
            #获取每个像素点的bgr值
            b = image[row, col, 0]  #blue
            g = image[row, col, 1]  #green
            r = image[row, col, 2]  #red\
            #给每个像素值设置新的bgr值
            image[row, col, 0] = clamp(b + s[0])
            image[row, col, 1] = clamp(g + s[1])
            image[row, col, 2] = clamp(r + s[2])
    return image

# 高斯模糊
def gaussian_blur(src):
    image = src
    dst = cv2.GaussianBlur(image, (0, 0), 2)
    return dst

img = cv2.imread("shefengdie.jpg")
# 水平翻转
# saveImg = cv2.flip(img, 1)
# 调节亮度
# saveImg = random_hsv_transform(img, 1, 0.1, 0.2)
# 高斯噪声
# saveImg = gaussian_noise(img)
# 高斯模糊
saveImg = gaussian_blur(img)

cv2.imwrite("./shefengdie_blur.jpg", saveImg)












